<?php 
class Professor_Model extends CI_Model
{
	private $tbl = 'professor';
	public function __construct()
	{
		parent::__construct();
		$this->load->database();
	}

	public function get($id = null){
		$this->load->database();
		

		if ($id === null){
			$query = $this->db->get($this->tbl);

			return $query->result_array();

		}

		$query = $this->db->get_where($this->tbl, array('matricula' => $id));

		return $query->row_array();
	}

	public function define_professor(){

		$data = array(
				'matricula' => $this->input->post('matricula'),
				'Nome'  => $this->input->post('Nome'),
				'perfil_id'  => $this->input->post('perfil_id')
		);

		return $this->db->insert($this->tbl, $data);
	}
	
	public function update_professor(){
	
		$data = array(
				
				'matricula' => $this->input->post('matricula'),
				'Nome'  => $this->input->post('Nome'),
				'perfil_id'  => $this->input->post('perfil_id')

		);
		
		$this->db->where('matricula',$this->input->post('matricula_antiga'));
		return $this->db->update($this->tbl, $data);
	}
	

	public function apaga ($id){
		$this->db->delete($this->tbl ,array('matricula' => $id));
	}

	public function get_paged_list($limit = 10, $offset = 0){
		$this->db->order_by('nome','asc');
		return $this->db->get($this->tbl, $limit, $offset);
	}

	function get_by($field, $data){
		$this->db->where($field, $data);
		return $this->db->get($this->tbl);
	}
	
	private function SendResult($result)
	{
		return $this->result_type != 'array' ? $result->result() : $result->result_array();
	}
	
	function get_where($select_array)
	{
		foreach ($select_array as $key => $value)
			$this->db->where($key, $value);
		$query = $this->db->get($this->tbl);
		return $query->result_array();
	}
}
?>